<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑爬虫源</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
   {% include 'navbar.html' %}
    <div class="container mt-5">
        <h1>编辑爬虫源</h1>
        <form action="{{ url_for('edit_source', source_id=source.id) }}" method="POST">
            <div class="form-group">
                <label for="source_name">源站名称</label>
                <input type="text" class="form-control" id="source_name" name="source_name" value="{{ source.source_name }}" required>
            </div>

            <div class="form-group">
                <label>爬取规则（JSON）</label>
                <div class="form-row">
                    <div class="col">
                        <label for="book_list_url">书籍列表 URL</label>
                        <input type="text" class="form-control" id="book_list_url" name="book_list_url" value="{{ rules.bookListUrl if rules.bookListUrl else '' }}">
                    </div>
                    <div class="col">
                        <label for="book_id_pattern">书籍 ID 匹配</label>
                        <input type="text" class="form-control" id="book_id_pattern" name="book_id_pattern" value="{{ rules.bookIdPattern if rules.bookIdPattern else '' }}">
                    </div>
                </div>
                <div class="form-row mt-2">
                    <div class="col">
                        <label for="page_pattern">页面匹配</label>
                        <input type="text" class="form-control" id="page_pattern" name="page_pattern" value="{{ rules.pagePattern if rules.pagePattern else '' }}">
                    </div>
                    <div class="col">
                        <label for="book_detail_url">书籍详情 URL</label>
                        <input type="text" class="form-control" id="book_detail_url" name="book_detail_url" value="{{ rules.bookDetailUrl if rules.bookDetailUrl else '' }}">
                    </div>
                </div>
                <div class="form-row mt-2">
                    <div class="col">
                        <label for="book_name_pattern">书籍名称匹配</label>
                        <input type="text" class="form-control" id="book_name_pattern" name="book_name_pattern" value="{{ rules.bookNamePattern if rules.bookNamePattern else '' }}">
                    </div>
                    <div class="col">
                        <label for="author_name_pattern">作者名称匹配</label>
                        <input type="text" class="form-control" id="author_name_pattern" name="author_name_pattern" value="{{ rules.authorNamePattern if rules.authorNamePattern else '' }}">
                    </div>
                </div>
                <div class="form-row mt-2">
                    <div class="col">
                        <label for="pic_url_pattern">图片 URL 匹配</label>
                        <input type="text" class="form-control" id="pic_url_pattern" name="pic_url_pattern" value="{{ rules.picUrlPattern if rules.picUrlPattern else '' }}">
                    </div>
                    <div class="col">
                        <label for="desc_start">描述开始</label>
                        <input type="text" class="form-control" id="desc_start" name="desc_start" value="{{ rules.descStart if rules.descStart else '' }}">
                    </div>
                </div>
                <div class="form-row mt-2">
                    <div class="col">
                        <label for="desc_end">描述结束</label>
                        <input type="text" class="form-control" id="desc_end" name="desc_end" value="{{ rules.descEnd if rules.descEnd else '' }}">
                    </div>
                    <div class="col">
                        <label for="book_index_url">书籍目录 URL</label>
                        <input type="text" class="form-control" id="book_index_url" name="book_index_url" value="{{ rules.bookIndexUrl if rules.bookIndexUrl else '' }}">
                    </div>
                </div>
                <div class="form-row mt-2">
                    <div class="col">
                        <label for="index_id_pattern">目录 ID 匹配</label>
                        <input type="text" class="form-control" id="index_id_pattern" name="index_id_pattern" value="{{ rules.indexIdPattern if rules.indexIdPattern else '' }}">
                    </div>
                    <div class="col">
                        <label for="index_name_pattern">目录名称匹配</label>
                        <input type="text" class="form-control" id="index_name_pattern" name="index_name_pattern" value="{{ rules.indexNamePattern if rules.indexNamePattern else '' }}">
                    </div>
                </div>
                <div class="form-row mt-2">
                    <div class="col">
                        <label for="book_content_url">书籍内容 URL</label>
                        <input type="text" class="form-control" id="book_content_url" name="book_content_url" value="{{ rules.bookContentUrl if rules.bookContentUrl else '' }}">
                    </div>
                    <div class="col">
                        <label for="content_start">内容开始</label>
                        <input type="text" class="form-control" id="content_start" name="content_start" value="{{ rules.contentStart if rules.contentStart else '' }}">
                    </div>
                </div>
                <div class="form-row mt-2">
                    <div class="col">
                        <label for="content_end">内容结束</label>
                        <input type="text" class="form-control" id="content_end" name="content_end" value="{{ rules.contentEnd if rules.contentEnd else '' }}">
                    </div>
                </div>
            </div>

            <div class="form-group mt-3">
                <label for="source_status">源站状态</label>
                <select class="form-control" id="source_status" name="source_status" required>
                    <option value="0" {% if source.source_status == 0 %}selected{% endif %}>关闭</option>
                    <option value="1" {% if source.source_status == 1 %}selected{% endif %}>开启</option>
                </select>
            </div>

            <button type="submit" class="btn btn-primary">保存更改</button>
        </form>
    </div>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
